package com.demo.constant;

import com.demo.config.ApolloSettings;
import com.demo.config.PreparedData;
import com.demo.config.ProjectSettings;
import com.demo.config.SQLSettings;

import java.util.Properties;

public class DBConstant {
    private static final String DATABASE = ProjectSettings.getInstance().getProperty("environment");
    private static final String SECREDT_KEY = SQLSettings.getInstance().getProperty("secretKey");
    private static Properties sqlSetting = SQLSettings.getInstance();
    private static Properties projectSetting = ProjectSettings.getInstance();
    private static Properties dataSetting = PreparedData.getInstance();

    public static String getDATABASE() {
        return DATABASE;
    }

    /**
     * SQL info
     * @return
     */
    public static String getHomerUsername() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.dbConfgEntity().getProperty("HOMERUsername") : sqlSetting.getProperty("DB_HOMER_USERNAME");
    }

    public static String getHomerPassword() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.dbConfgEntity().getProperty("HOMERPassword") : sqlSetting.getProperty("DB_HOMER_PASSWORD");
    }

    public static String getHpUsername() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.dbConfgEntity().getProperty("HPUsername") : sqlSetting.getProperty("DB_HP_USERNAME");
    }

    public static String getHpPassword() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.dbConfgEntity().getProperty("HPPassword") : sqlSetting.getProperty("DB_HP_PASSWORD");
    }

    public static String getCuUsername() {
        if (DATABASE.equalsIgnoreCase("PROD")) {
            return projectSetting.getProperty("DataSource").equals("online") ?
                    ApolloSettings.dbConfgEntity().getProperty("CUUsername") : sqlSetting.getProperty("PROD_CU_USERNAME");
        }
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.dbConfgEntity().getProperty("CUUsername") : sqlSetting.getProperty("DB_CU_USERNAME");
    }

    public static String getCuPassword() {
        if (DATABASE.equalsIgnoreCase("PROD")) {
            return projectSetting.getProperty("DataSource").equals("online") ?
                    ApolloSettings.dbConfgEntity().getProperty("CUPassword") : sqlSetting.getProperty("PROD_CU_PASSWORD");
        }
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.dbConfgEntity().getProperty("CUPassword") : sqlSetting.getProperty("DB_CU_PASSWORD");
    }

    public static String getMappUsername() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.dbConfgEntity().getProperty("MAPPUsername") : sqlSetting.getProperty("DB_MAPP_USERNAME");
    }

    public static String getMappPassword() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.dbConfgEntity().getProperty("MAPPPassword") : sqlSetting.getProperty("DB_MAPP_PASSWORD");
    }

    /**
     * customer info
     * @return
     */
    public static String getCusmerIdCard(){
        return projectSetting.getProperty("DataSource").equals("online") ?
                Encrypt.decryptDecode(ApolloSettings.accountConfgEntity().getProperty("PersonIdCard"), getSecredtKey()) : dataSetting.getProperty("register_customerIdent");
    }

    public static String getRegisterPhoneNumber(){
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.accountConfgEntity().getProperty("PersonPhoneNumber") : dataSetting.getProperty("register_phoneNumber") ;
    }
    public static String getCustomerName() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.accountConfgEntity().getProperty("PersonName") : dataSetting.getProperty("register_customerName");
    }

    public static String getCommonPerson() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                Encrypt.decryptDecode(ApolloSettings.accountConfgEntity().getProperty("PersonId"), getSecredtKey()) : dataSetting.getProperty("common_person");
    }

    public static String getStrategyOrbp() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.accountConfgEntity().getProperty("StrategyOrbp") : ORBPStrategyPhoneTypeEnum.MW_Approve.getphoneNumber();
    }

    public static String getStrategyAF() {
        return projectSetting.getProperty("DataSource").equals("online") ?
                ApolloSettings.accountConfgEntity().getProperty("StrategyAF") : AFStrategyPhoneTypeEnum.echeckApprove.getphoneNumber();
    }

    public static String getSecredtKey() {
        return SECREDT_KEY;
    }
}
